import React, { Component } from 'react';
import { Router, Route, hashHistory, IndexRedirect } from 'react-router';
import App from '../App';
import Page from '../components/Page';
import Index from '../components/Index';
import Login from '../components/pages/Login';

/*const Wysiwyg = (location, cb) => {     // 按需加载富文本配置
    require.ensure([], require => {
        cb(null, require('../components/ui/Wysiwyg').default);
    }, 'Wysiwyg');
};*/
import { LocaleProvider } from 'antd';
import zhCN from 'antd/lib/locale-provider/zh_CN';

export default class CRouter extends Component {
    requireAuth = (permission, component) => {
        const { store } = this.props;
        const { auth } = store.getState().httpData;
        if (!auth || !auth.data.permissions.includes(permission)) window.location.hash = '/404';
        return component;
    };
    render() {
        return (
            <LocaleProvider locale={zhCN}>
                <Router history={hashHistory}>
                    <Route path={'/'} components={Page}>
                        <IndexRedirect to="/app/index" />
                        <Route path={'app'} component={App}>
                            <Route path={'index'} component={Index} />
                        </Route>
                        {/*<Route path={'base'} component={AppBase}>
                            <Route path={'expert'}>
                                <Route path={'info/:id/:source'} component={ExpertInfo} />
                            </Route>
                            <Route path={'service'}>
                                <Route path={'index'} component={ServiceIndex} />
                            </Route>
                            <Route path={'talent'}>
                                <Route path={'project/interest'} component={TalentProjectInterest} />
                            </Route>
                            <Route path={'issue'}>
                                <Route path={'list'} component={IssueList} />
                                <Route path={'edit'} component={IssueFrom} />
                            </Route>
                        </Route>*/}
                    </Route>
                    <Route path={'login'} component={Login} />
                </Router>
            </LocaleProvider>
        )
    }
}
